<template>
  <!-- 新增见证事项 -->
  <el-dialog
    :title="dialogTitle"
    draggable
    :modal="matterType !== 'add'"
    :penetrate="true"
    :close-on-click-modal="false"
    :visible.sync="visible"
    width="850px"
    @close="closeFn"
    class="position-left"
  >
    <!-- {{ matterType }} -->
    <!-- {{ id }} -->
    <v-work-task-list
      v-if="matterType === 'add'"
      ref="dialogTaskList"
      :cid="id"
      :add-task-show="false"
      @initFromFn="initFn"
      @selectedTaskFn="selectedTaskFn"
      @fatherMethod="fatherMethod"
      @fatherNodeTab="fatherNodeTab"
      :task-active.sync="topTaskActive"
      :visible.sync="visible"
      :init-data="initData"
    />
    <!-- 表单缓存-重构 -->
    <!-- {{ topTaskActive }}
      :task-active="topTaskActive" -->
    <vWorkBenchAddForm
      v-if="visible"
      ref="vWorkBenchAddForm"
      :model="addform"
      :rules="rules"
      :matter-type="matterType"
      :init-data="initData"
      :curr-data="currProjectData"
      :cid="id"
      :visible.sync="visible"
      :show="show"
      @close="closeFn"
      @isProjectChange="setHiddenHint"
    ></vWorkBenchAddForm>
    <!-- <div class="ui-mt20 ui-mr10">
    </div> -->
<!--    <div class="ui-mt20 ui-mr10">-->
<!--      &lt;!&ndash; dataStatus  INVALID 枚举值: INVALID,VALID,TEMP,DELETE,ARCHIVE-->
<!--matterCode  见证事项编码-->
<!--matterStatus   见证事项状态 枚举值: NORMAL_TYPE,EXCEPTION_TYPE-->
<!--source  见证记录来源-->
<!--witnessRecordDesc  见证记录描述-->
<!--witnessRecordTime  记录时间-->
<!--witnessSubTaskId  见证子任务id-->
<!--witnessTaskId  见证任务id-->
<!--响应内容 &ndash;&gt;-->
<!--      &lt;!&ndash; if (this.matterType === "STOP") {-->
<!--            this.dialogTitle = "新增暂停事项";-->
<!--          }-->
<!--          if (this.matterType === "RECOVER") {-->
<!--            this.dialogTitle = "新增恢复事项";-->
<!--          } &ndash;&gt;-->
<!--      &lt;!&ndash; <el-alert v-if="alertMatterFlag" class="ui-mb10" :closable="false" type="warning" show-icon>-->
<!--        <span slot="title">-->
<!--          <template>当前环节还未设置</template>-->
<!--          <span v-if="matterType === 'STOP'">暂停</span>-->
<!--          <span v-if="matterType === 'RECOVER'">恢复</span>-->
<!--          <template>见证事项，请联系管理员在【系统管理-见证事项管理】中添加</template>-->
<!--        </span>-->
<!--      </el-alert> &ndash;&gt;-->
<!--      <el-form ref="addform" grid :model="addform" :rules="rules" label-width="90px" :inline="false" size="normal">-->
<!--        <el-form-item v-if="matterType === 'add'" :span="24" label="见证场景" required prop="witnessScene">-->
<!--          <el-select-->
<!--            style="width: 100%"-->
<!--            v-model="addform.witnessScene"-->
<!--            placeholder="请选择"-->
<!--            @change="witnessSceneChangeFn"-->
<!--          >-->
<!--            <el-option-->
<!--              v-for="item in witnessSceneOptions"-->
<!--              :key="item.value"-->
<!--              :label="item.label"-->
<!--              :value="item.value"-->
<!--            ></el-option>-->
<!--          </el-select>-->
<!--        </el-form-item>-->
<!--        <el-form-item :span="24" label="见证事项" required prop="taskMatterCode">-->
<!--          &lt;!&ndash; {{ witnessMatterOptions }} &ndash;&gt;-->
<!--          &lt;!&ndash; {{ addform.taskMatterCode }} &ndash;&gt;-->
<!--          <el-cascader-->
<!--            v-model="addform.taskMatterCode"-->
<!--            style="width: 100%"-->
<!--            option-max-width="702px"-->
<!--            :options="witnessMatterOptions"-->
<!--            @change="taskMattterCodeChangeFn"-->
<!--            @focus="matterFocusFn"-->
<!--          />-->
<!--          <span v-if="alertMatterFlag" class="witness-matter-warning">-->
<!--            暂未配置，请联系管理员在【系统管理-见证事项管理】中添加-->
<!--          </span>-->
<!--        </el-form-item>-->
<!--        <el-form-item :span="12" label="状态" prop="status">-->
<!--          <i style="color: #e82f2f; position: relative; right: 48px">*</i>-->
<!--          <el-radio-group v-model="addform.matterStatus" @change="matterStatusChangeFn">-->
<!--            <el-radio label="NORMAL_TYPE">正常</el-radio>-->
<!--            <el-radio label="EXCEPTION_TYPE">异常</el-radio>-->
<!--          </el-radio-group>-->
<!--          &lt;!&ndash; 暂时隐藏预警级别 22-3-25 &ndash;&gt;-->
<!--          &lt;!&ndash; <el-cascader-->
<!--            v-model="addform.warningLevel"-->
<!--            style="margin-left: 10px"-->
<!--            placeholder="选择等级"-->
<!--            option-max-width="150px"-->
<!--            class="ui-w120"-->
<!--            :options="initData.recordExceStatusEnum"-->
<!--            :disabled="addform.matterStatus === 'NORMAL_TYPE'"-->
<!--            @change="handleErrorLevelChangeFn"-->
<!--          /> &ndash;&gt;-->
<!--        </el-form-item>-->
<!--        &lt;!&ndash; {{ matterInstruction }} &ndash;&gt;-->
<!--        &lt;!&ndash; {{ addform.itemCodeList }} &ndash;&gt;-->
<!--        <el-form-item :span="24" label="事项说明" required prop="itemCodeList">-->
<!--          <el-cascader-->
<!--            v-model="addform.itemCodeList"-->
<!--            style="width: 100%"-->
<!--            option-max-width="702px"-->
<!--            :props="{ multiple: false }"-->
<!--            :options="matterInstruction"-->
<!--            @change="itemColeListChangeFn"-->
<!--          />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="发生时间" v-if="matterType === 'add'" prop="occurrentTime" :span="12">-->
<!--          <el-date-picker-->
<!--            v-model="addform.occurrentTime"-->
<!--            style="width: 100%"-->
<!--            unlink-panels-->
<!--            type="datetime"-->
<!--            :clearable="true"-->
<!--            format="yyyy-MM-dd HH:mm:ss"-->
<!--            value-format="yyyy-MM-dd HH:mm:ss"-->
<!--            :picker-options="pickerOptions"-->
<!--            @click-now="clickNowFn"-->
<!--          />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="附件信息" :span="24">-->
<!--          <el-upload-->
<!--            class="file-upload-dialog"-->
<!--            ref="fireUploadDialog"-->
<!--            action=""-->
<!--            :limit="10"-->
<!--            :on-exceed="handleExceed"-->
<!--            :before-remove="beforeRemoveFn"-->
<!--            :before-upload="beforeUploadImage"-->
<!--            :on-remove="onRemoveFn"-->
<!--            accept=".pdf,.jpg,.png,.jpeg,.gif"-->
<!--            :http-request="uploadFileFn"-->
<!--            :on-success="onUploadSuccessFn"-->
<!--            :on-error="onUploadFailedFn"-->
<!--          >-->
<!--            <el-button size="small" icon="el-icon-plus" type="primary" style="width: 100%" dashed>点击上传</el-button>-->
<!--          </el-upload>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="见证记录" required prop="witnessRecordDesc" :span="24">-->
<!--          <el-input-->
<!--            v-model.trim="addform.witnessRecordDesc"-->
<!--            type="textarea"-->
<!--            style="width: 100%"-->
<!--            :rows="4"-->
<!--            maxlength="200"-->
<!--            show-word-limit-->
<!--          />-->
<!--        </el-form-item>-->
<!--      </el-form>-->
<!--    </div>-->
    <span slot="footer">
      <div class="warn-tip ui-mb10" v-if="matterType === 'add' && ! hiddenHint">
        <i class="el-icon-warning" />
        <span>提交只针对【当前所选标段】信息提交</span>
      </div>
      <el-button
        v-if="matterType === 'STOP' || matterType === 'RECOVER'"
        type="primary"
        :loading="loading"
        @click="submitRecordFn('close')"
      >
        提交
      </el-button>
      <el-button v-if="matterType === 'add'" type="primary" :loading="loading" @click="submitRecordFn('close')">
        提交并关闭
      </el-button>
      <el-button v-if="matterType === 'add'" type="primary" :loading="loading" @click="submitRecordFn">提交</el-button>
      <el-button @click="cancelFn()">取消</el-button>
    </span>
  </el-dialog>
</template>
<script>
  import {
    subtaskReview,
    witnessRecordAdd,
    stopWitness,
    recoverWitness,
    itemDictList,
    uploadFile,
    witnessRecordList,
    witnessItemRuleGetTime
  } from "../../api/api";
  import vWorkTaskList from "../../components/WorkTaskList.vue";
  import vWorkBenchAddForm from "../../components/dialog/WorkBenchAddForm.vue";
  export default {
    name: "WorkBenchAddMatters",
    components: { vWorkTaskList, vWorkBenchAddForm },
    props: {
      matterType: {
        type: String,
        default: "add"
      },
      initData: {
        type: Object,
        default() {
          return {};
        }
      },
      currData: {
        type: Object,
        default() {
          return {};
        }
      },
      topTaskActive: {
        type: String,
        default: ""
      },
      show: {
        type: Boolean,
        default: false
      }
    },
    data() {
      return {
        hiddenHint:false,
        dialogTitle: "新增见证事项",
        id: "",
        currProjectData: {},
        matterInstruction: [],
        pickerOptions: {
          disabledDate(time) {
            console.log("time", time);
            return false; // time.getTime() < Date.now();
          }
        },
        witnessSceneOptions: [], // 见证场景下拉列表
        witnessMatterOptions: [],
        alertMatterFlag: false,
        BaseInfoVisible: false,
        loading: false,
        visible: false,
        cardVisible: true,
        taskFormCache: {}, // 所有任务的表单缓存
        addform: {
          matterStatus: "NORMAL_TYPE",
          taskMatterCode: [],
          itemCodeList: [],
          witnessRecordDesc: "",
          occurrentTime: "",
          warningLevel: "",
          attachmentList: []
        },
        rules: {
          witnessScene: [{ required: true, message: "见证场景不能为空", trigger: "blur" }],
          taskMatterCode: [{ required: true, message: "见证事项不能为空", trigger: "blur" }],
          itemCodeList: [{ required: true, message: "事项说明不能为空", trigger: "blur" }],
          occurrentTime: [{ required: true, message: "发生时间不能为空", trigger: "blur" }],
          witnessRecordDesc: [
            {
              required: true,
              message: "见证记录不能为空",
              trigger: ["blur"]
            }
          ]
          // 预警级别校验暂时隐藏
          // status: [
          //   {
          //     message: "选择等级不能为空",
          //     validator: (rule, value, callback) => {
          //       console.log(value);
          //       if (this.addform.matterStatus !== "NORMAL_TYPE" && !this.addform.warningLevel) {
          //         callback(new Error("选择等级不能为空"));
          //       } else {
          //         callback();
          //       }
          //     },
          //     trigger: "blur"
          //   }
          // ]
          // keyWord: [{ required: true, message: "key不能为空", trigger: "blur" }],
        }
      };
    },
    computed: {
      // visible() {
      //   return this.show;
      // },
    },
    watch: {
      topTaskActive(val) {
        console.log("topTaskActive", val);
      },
      show(val) {
        this.visible = val;
        this.detailData = [];
        console.log("show", this.$route.query.id);
        // this.matterType = "add";
        if (val) {
          this.id = this.$route.query.id;
          if (this.matterType === "STOP") {
            this.dialogTitle = "新增暂停事项";
          }
          if (this.matterType === "RECOVER") {
            this.dialogTitle = "新增恢复事项";
          }
          if (this.matterType === "add") {
            this.dialogTitle = "新增见证事项";
          }
          this.currProjectData = this.currData;
          this.initFn();
        }
      }
    },
    methods: {
      setHiddenHint(hiddenHint){
        this.hiddenHint = hiddenHint
      },
      // wei父组件调用子组件方法
      childWorkList(id) {
        this.id = id;
        this.$refs.dialogTaskList.scrollView(id);
      },
      childWorkTab(tabName, tabId) {
        this.id = tabId;
        this.$refs.dialogTaskList.nodeTab(tabName, tabId);
      },
      // 子组件调用父组件方法
      fatherMethod(childObj) {
        this.id = childObj.child;
        this.$emit("scrollView", childObj);
      },
      fatherNodeTab(tab, queryId) {
        this.id = queryId;
        this.$emit("fatherNodeTab", tab, queryId);
      },
      // ----------------wei
      async initFn() {
        console.log("initFn");
        if (this.initFlag) {
          return;
        }
        this.initFlag = setTimeout(() => {
          clearTimeout(this.initFlag);
          this.initFlag = null;
        }, 300);
        // this.initFromFn();
        // await this.witnessRecordListAllFn();
        // await this.initParentCodeFn();
      },
      // 选中任务回调方法
      selectedTaskFn(currTaskData) {
        console.log("currTaskData", currTaskData);
        // 加入缓存上一个id
        // if (!this.taskFormCache[this.id]) {
        this.taskFormCache[this.id] = JSON.parse(JSON.stringify(this.addform));
        // }
        this.currProjectData = currTaskData;
        this.id = currTaskData.witnessSubTaskId;
        this.initFn();
      },
      // 见证记录-所有-添加时的禁用属性
      async witnessRecordListAllFn() {
        if (!this.id) {
          return;
        }
        const p = {
          witnessSubTaskId: this.id,
          pageSize: -1
        };
        this.recordDataAll = [];
        console.log("this.id", this.id);
        try {
          const res = await witnessRecordList(p);
          if (res.success) {
            this.recordDataAll = res.data.result;
          }
        } catch (error) {
          console.error(error);
        }
      },
      matterStatusChangeFn() {
        if (this.addform.matterStatus === "NORMAL_TYPE") {
          this.addform.warningLevel = "";
        }
        this.taskMattterCodeChangeFn();
      },
      itemColeListChangeFn(val) {
        console.log("val", val);
        console.log("this.matterInstruction", this.matterInstruction);
        // const obj = this.matterInstruction.find((itemC) => itemC.defaultItem === "DEFAULT");
        const obj = this.matterInstruction.find((item) => item.value === val[0]);
        this.addform.witnessRecordDesc = obj.record;
        this.$refs["addform"] && this.$refs["addform"].clearValidate();
      },
      // 见证场景
      witnessSceneChangeFn(e) {
        console.log("witnessSceneChange", e);
        // this.taskMattterCodeChangeFn();
        this.initFromFn();
        this.addform.witnessScene = e;
        this.matterFocusFn();
      },
      async taskMattterCodeChangeFn() {
        // TODO 这里要判断见证场景：人工见证事项支持多次选择
        // 预警级别逻辑暂时注释
        // if (this.addform.matterStatus === "NORMAL_TYPE") {
        //   this.$refs.addform.validateField("status");
        // }
        this.addform.itemCodeList = [];
        console.log("this.addform.taskMatterCode", this.addform.taskMatterCode);
        if (this.addform.taskMatterCode.length > 0 && this.addform.taskMatterCode[0]) {
          // this.$refs["addform"].resetFields();
          const p = {
            parentCode: this.addform.taskMatterCode[0] || -1,
            itemStatus: this.addform.matterStatus
          };
          // if (p.parentCode !=== -1) {
          // p.itemStatus = this.addform.matterStatus;
          // }
          this.matterInstruction = await this.itemDictListFn(p);
          console.log("this.matterInstruction", this.matterInstruction);
          console.log("this.addform.itemCodeList", this.addform.itemCodeList);
          if (this.matterInstruction && this.matterInstruction[0]) {
            const arr = this.matterInstruction.find((item) => item.defaultItem === "DEFAULT");
            this.addform.itemCodeList = [arr.value];
            this.addform.witnessRecordDesc = arr.record;
          }
        }
      },
      async matterFocusFn() {
        console.log("matterFocusFn");
        console.log("witnessMatterOptions");
        await this.witnessRecordListAllFn();
        await this.initParentCodeFn();
      },
      //  限制上传图片格式
      beforeUploadImage(file) {
        console.log("file.szie", file.size);
        console.log("file.type", file.type);
        const isSize = file.size / 1024 / 1024; // 文件大小
        const fileSize = 5;
        if (isSize > fileSize) {
          this.uploadFlag = true;
          // this.$message.error(`上传图片大小不能超过${fileSize}MB!`);
          this.$msgbox({
            title: "提示",
            message: `文件大小不能超过${fileSize}MB，请重新上传。`,
            type: "warning"
          });
          return false;
        }
        return true;
      },
      // 文件相关
      beforeRemoveFn(file) {
        if (!this.uploadFlag) {
          return this.$confirm(`确定移除 ${file.name}？`, "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          });
        }
      },
      onRemoveFn(file) {
        for (const [index, item] of this.addform.attachmentList.entries()) {
          if (item.uid === file.uid) {
            this.addform.attachmentList.splice(index, 1);
            return;
          }
        }
      },
      async uploadFileFn(params) {
        try {
          const form = new FormData();
          form.append("file", params.file);
          const res = await uploadFile(form);
          if (res.success) {
            this.addform.attachmentList.push({
              ...params.file,
              attachId: res.data
            });
          }
        } catch (error) {
          console.error(error);
          this.$message({
            type: "error",
            message: "上传文件失败，请稍后再试",
            single: true
          });
        }
      },
      onUploadSuccessFn() {
        this.$message({
          type: "success",
          message: "上传文件成功!",
          single: true
        });
      },
      handleExceed() {
        // files, fileList
        this.$message.warning(`当前限制最多上传 10 个文件`);
      },
      onUploadFailedFn() {
        this.$message({
          type: "error",
          message: "上传文件失败，请稍后再试",
          single: true
        });
      },
      handleErrorLevelChangeFn() {
        this.$refs.addform.validateField("status");
      },
      handleClickAddFn() {
        document.getElementsByClassName("el-upload__input")[0].click();
      },
      addMattersSubmitFn(e) {
        console.log("e", e);
      },
      initFromFn() {
        this.recordData = [];
        this.activities = [];
        this.sideRecordActive = "first";
        this.$refs["fireUploadDialog"] && this.$refs["fireUploadDialog"].clearFiles();
        // this.pageObj.currentPage = 1;
        // this.pageQueryList.currentPage = 1;
        this.loading = false;
        this.submitLoading = false;
        // 初始化 表单
        this.addform.witnessScene = "PEOPLE";
        this.addform.taskMatterCode = "";
        this.addform.matterStatus = "NORMAL_TYPE";
        this.addform.witnessRecordDesc = "";
        // TODO 这里要改服务器时间
        if (!this.addform.occurrentTime) {
          this.addform.occurrentTime = this.$moment(new Date()).format("yyyy-MM-DD HH:mm:ss");
        }
        this.addform.itemCodeList = [];
        this.addform.warningLevel = "";
        this.addform.attachmentList = []; // 附件列表
        this.witnessMatterOptions = [];
        this.witnessSceneOptions = this.initData.witnessScene;
        this.matterInstruction = [];
        if (!this.addform.occurrentTime) {
          this.witnessItemRuleGetTimeFn();
        }
        console.log("this.addform", this.addform);
        // this.$refs["addform"] && this.$refs["addform"].clearValidate();
        this.$refs["addform"] && this.$refs["addform"].resetFields();
      },
      // 见证记录-所有-添加时的禁用属性 这里废弃了 by link 20220822
      async witnessItemRuleGetTimeFn() {
        const p = {};
        console.log("this.id", this.id);
        try {
          const res = await witnessItemRuleGetTime(p);
          console.log("res_time", res);
          if (res.success) {
            this.addform.occurrentTime = res.data;
            // return res.data;
          }
        } catch (error) {
          console.error(error);
        }
      },
      async initParentCodeFn() {
        // TODO 人工见证事项 -》获取 见证事项列表
        const p = { parentCode: -1 };
        if (this.matterType === "STOP") {
          p.witnessScene = "STOP";
        } else if (this.matterType === "RECOVER") {
          p.witnessScene = "RECOVER";
        }
        const arr = await this.itemDictListFn(p);
        /* 这里需要判断，添加、暂停、恢复 */
        if (this.matterType === "STOP" || this.matterType === "RECOVER") {
          this.$set(this, "witnessMatterOptions", arr);
        } else {
          this.$set(this, "witnessMatterOptions", this.refreshOptionsFn(arr));
        }
        console.log("this.witnessMatterOptions", this.witnessMatterOptions);
        // console.log('');
        // 只有一个选项，作为默认选项 by link 20220702
        if (this.witnessMatterOptions && this.witnessMatterOptions.length === 1) {
          this.addform.taskMatterCode = [this.witnessMatterOptions[0].value];
          this.addform.witnessRecordDesc = this.witnessMatterOptions[0].record;
          this.taskMattterCodeChangeFn();
          // this.addform.itemCodeList = [this.matterInstruction[0].value];
        }
        // 如果为空提示显示
        this.alertMatterFlag = !this.witnessMatterOptions.length;
      },
      // 刷新见证事项的状态
      refreshOptionsFn(arr) {
        return arr.map((item) => {
          const flag = this.recordDataAll.some(
            (recordItem) =>
              // console.log(recordItem.data.parentItemCode, item.value);
              recordItem.data.parentItemCode === item.value
          );
          if (flag) {
            item.disabled = true;
          }
          return item;
        });
      },
      // 见证事项-列表
      async itemDictListFn(p = {}) {
        // let p = {
        //   parentCode: this.addform.taskMatterCode[0] || -1,
        // };
        // if (p.parentCode !== -1) {
        //   p.itemStatus = this.addform.matterStatus;
        // }
        if (!this.id) {
          return;
        }
        p.witnessSubTaskId = this.id;
        try {
          const res = await itemDictList(p);
          if (res.success) {
            this.itemDictListData = res.data.map((item) => ({
              label: item.itemName,
              value: item.itemCode,
              defaultItem: item.defaultItem,
              record: item.record
            }));
            return this.itemDictListData;
          }
          this.$message({
            type: "error",
            message: res.message || "获取数据失败，请稍后再试",
            single: true
          });
        } catch (err) {
          console.error(err);
          this.$message({
            type: "error",
            message: "获取数据失败，请稍后再试",
            single: true
          });
        }
      },
      // 见证事项-提交
      submitRecordFn(flag) {
        console.log("addform_", `${this.matterType}`);
        this.$refs["vWorkBenchAddForm"].formValidateFn(flag, this.matterType);
        // this.$refs.addform.validate((valid) => {
        //   if (valid) {
        // this.loading = true;
        // this.submitLoading = true;
        // setTimeout(() => {
        //   this.loading = false;
        //   this.submitLoading = false;
        // }, 3000);
        //     this.witnessRecordAddFn(flag);
        //   } else {
        //     console.log("error submit!!");
        //     return false;
        //   }
        // });
      },
      // 见证事项-新增
      async witnessRecordAddFn(flag) {
        console.log("close", flag);
        // dataStatus INVALID
        // 枚举值: INVALID,VALID,TEMP,DELETE,ARCHIVE
        // itemCode 见证事项编码
        // itemStatus NORMAL_TYPE
        // 见证事项状态 枚举值: NORMAL_TYPE,EXCEPTION_TYPE
        // source 见证记录来源
        // witnessRecordDesc 见证记录描述
        // witnessRecordTime 记录时间
        // witnessSubTaskId 见证子任务id
        // witnessTaskId
        let p = {};
        // if (params) {
        //   // 复核调新增
        //   p = params;
        // } else {
        const itemCodes = this.addform.itemCodeList.map((item) => item);
        if (this.matterType === "add") {
          this.addform.occurrentTime;
        }
        p = {
          itemCodes,
          witnessScene: this.addform.witnessScene,
          itemStatus: this.addform.matterStatus,
          witnessRecordDesc: this.addform.witnessRecordDesc,
          occurrentTime: this.addform.occurrentTime,
          // 预警级别暂时写死 22-3-25
          warningLevel: this.matterStatus === "NORMAL_TYPE" ? "" : "HEIGHT",
          // warningLevel: this.matterStatus === "NORMAL_TYPE" ? "" : this.addform.warningLevel[0],
          attachmentList: this.addform.attachmentList.map((item) => item.attachId),
          witnessSubTaskId: this.currProjectData.witnessSubTaskId,
          witnessTaskId: this.currProjectData.witnessTaskId,
          source: this.$store.getters.username || localStorage.getItem("username")
        };
        // }
        try {
          let res = null;
          if (this.matterType === "STOP") {
            res = await stopWitness(p);
          } else if (this.matterType === "RECOVER") {
            res = await recoverWitness(p);
          } else {
            res = await witnessRecordAdd(p);
          }
          if (res.success) {
            // this.addform.itemCodeList = [];
            // if (!params) {
            this.addform.witnessRecordDesc = "";
            this.addform.matterStatus = "NORMAL_TYPE";
            this.addform.warningLevel = "";
            this.addform.attachmentList = [];
            this.matterInstruction = [];
            this.$refs["addform"].resetFields();
            this.$refs["fireUploadDialog"].clearFiles();
            // this.pageObj.currentPage = 1; // 当前页数
            // }
            if (flag === "close") {
              this.$emit("close", "save");
            }
            this.initFn();
            // this.witnessRecordListFn(); //更新列表 1、添加后刷新；2、复核保存后刷新
            this.$message({
              type: "success",
              message: res.message || "添加成功",
              single: true
            });
            // if (flag === "close") {
            //   this.$emit("close", "save");
            // }
            // this.initFn();
          } else {
            this.$message({
              type: "error",
              message: res.message || "获取数据失败，请稍后再试",
              single: true
            });
          }
        } catch (err) {
          console.error(err);
          this.$message({
            type: "error",
            message: "获取数据失败，请稍后再试",
            single: true
          });
        }
        this.loading = false;
        this.submitLoading = false;
      },
      cancelFn() {
        this.visible = false;
      },
      closeFn(flag) {
        this.BaseInfoVisible = false;
        this.keyWord = "";
        this.$emit("close", flag);
      },
      async submitFn() {
        this.loading = true;
        // let witnessSubTaskId = [];
        await this.subtaskReviewFn();
        this.$emit("submit");
      },
      submitSearchFn() {},
      // 审核见证
      async subtaskReviewFn() {
        try {
          this.recordSelected;
          console.log("this.recordSelected", this.recordSelected);
          const recordIds = Object.values(this.recordSelected);
          console.log("recordIds", recordIds);
          // return;
          const p = {
            // witnessTaskId: this.rowData.witnessTaskId,
            recordIds, // 要删除的记录
            witnessSubTaskId: this.rowData.witnessSubTaskId
          };
          // if (p.recordIds.length == 0) {
          //   this.loading = false;
          //   return;
          // }
          const res = await subtaskReview(p);
          if (res.success) {
            this.loading = false;
            // 显示查看见证记录
            this.$message({
              type: "success",
              message: res.message || "操作成功",
              single: true
            });
            // this.detailData = res.data;
          } else {
            this.$message({
              type: "error",
              message: res.message || "获取数据失败，请稍后再试",
              single: true
            });
          }
        } catch (error) {
          this.$message({
            type: "error",
            message: "获取数据失败，请稍后再试",
            single: true
          });
        }
        this.visible = false;
      },
      // 提交
      async subtaskAllocateUserFn() {}
    }
  };
</script>
<style lang="scss" scoped>
  .witness-matter-warning {
    position: absolute;
    height: 14px;
    overflow: hidden;
    width: 120%;
    left: 0;
    top: 34px;
    color: $orange;
    line-height: 14px;
    font-size: 12px;
    z-index: 9;
    background: #fff;
  }
  .fire-upload-dialog {
    width: 100%;
    ::v-deep .el-upload {
      width: 100%;
    }
  }
  .position-left {
    ::v-deep .el-dialog__body {
      max-height: 465px !important;
    }
  }
  .daishenhe-tag {
    position: absolute;
    top: 60px;
    right: 15px;
    i {
      font-size: 70px;
      color: $primary;
    }
  }
  .ui-table th,
  .ui-table td {
    width: 275px;
  }
  .position-left {
    position: absolute;
  }
  .position-left {
    ::v-deep .el-dialog__body {
      max-height: 465px !important;
    }
  }
  .warn-tip {
    position: absolute;
    bottom: 14px;
    i {
      color: #fc9306;
      font-size: 18px;
    }
    span {
      font-size: 16px;
      color: #333333;
      padding-left: 5px;
    }
  }
  .verification-warn-tip {
    font-size: 12px;
    width: 365px;
    font-family: MicrosoftYaHei;
    color: #fc9306;
    line-height: 19px;
    margin-bottom: -15px;
  }
</style>

<style lang="scss">

.el-popper{
  .el-cascader-node{
    height: auto;
    min-height: 34px;
    .el-cascader-node__label{
      word-break: break-all;
      white-space: normal;
      flex: 1;
      padding: 0 10px;
      margin: 4px auto;
      line-height: 15px;
    }
  }
}
</style>
